<? 
	$title="Edit User Role"; 
	$mid="5";
	
	require("required/dbconnect.php"); 
	
	require_once("required/function.php");
	checkAccess("allow_user_management",1);
	
	if(isset($_POST['btnsubmit']))
	{
		$id=$_POST['id'];
		$role_name=mysql_escape_string($_POST['role_name']);
		
		$update=mysql_query("update os_user_role set  
						`allow_statistic_view` = '0',
						`allow_content_management` = '0',
						`allow_product_management` = '0',
						`allow_product_category` = '0',
						`allow_product_add` = '0',
						`allow_product_edit` = '0',
						`allow_product_delete` = '0',
						`allow_gift_management` = '0',
						`allow_shopping_management` = '0',
						`allow_branch_management` = '0',
						`allow_branch_member_view` = '0',
						`allow_branch_member_add` = '0',
						`allow_branch_member_edit` = '0',
						`allow_branch_member_delete` = '0',
						`allow_online_member_view` = '0',
						`allow_online_member_edit` = '0',
						`allow_online_member_delete` = '0',
						`allow_branch_sales_view` = '0',
						`allow_branch_sales_edit` = '0',
						`allow_branch_sales_delete` = '0',
						`allow_branch_sales_add` = '0',
						`allow_online_sales_view` = '0',
						`allow_online_sales_edit` = '0',
						`allow_online_sales_delete` = '0',
						`allow_user_management` = '0',
						`allow_shipping_management` = '0',
						`allow_system_management` = '0' where id=$id");
		
		$query="update os_user_role set role_name = '$role_name',";
		
		if(!empty($_POST['accessright']))
		{
			$accessright=$_POST['accessright'];
			
			for($i=0;$i<count($accessright);$i++)
			{
				$query.=$accessright[$i]."=1,";	
			}			
			
		}
		
		$query=rtrim($query,",")." where id=$id";
		
		
		
		mysql_query($query)or die(mysql_error());
		header("Location:user_role_view_all.php?action=3");
		
	}
	else
	{
	
		require("required/header.php");	
		$id=$_GET['id'];		
		
		$get_data=mysql_query("select * from os_user_role where id=$id");
		$a=mysql_fetch_array($get_data,MYSQL_ASSOC);
		$allow_statistic_view_chk=convertChecked($a['allow_statistic_view']);
		$allow_content_management_chk=convertChecked($a['allow_content_management']);
		$allow_user_management_chk=convertChecked($a['allow_user_management']);
		$allow_system_management_chk=convertChecked($a['allow_system_management']);
		$allow_shipping_management_chk=convertChecked($a['allow_shipping_management']);
		$allow_product_management_chk=convertChecked($a['allow_product_management']);
		$allow_product_category_chk=convertChecked($a['allow_product_category']);
		$allow_product_add_chk=convertChecked($a['allow_product_add']);
		$allow_product_edit_chk=convertChecked($a['allow_product_edit']);
		$allow_product_delete_chk=convertChecked($a['allow_product_delete']);
		
		$allow_gift_management_chk=convertChecked($a['allow_gift_management']);
		
		$allow_shopping_management_chk=convertChecked($a['allow_shopping_management']);
		
		$allow_branch_management_chk=convertChecked($a['allow_branch_management']);
		$allow_branch_member_view_chk=convertChecked($a['allow_branch_member_view']);
		$allow_branch_member_add_chk=convertChecked($a['allow_branch_member_add']);
		$allow_branch_member_edit_chk=convertChecked($a['allow_branch_member_edit']);
		$allow_branch_member_delete_chk=convertChecked($a['allow_branch_member_delete']);
		
		$allow_online_member_view_chk=convertChecked($a['allow_online_member_view']);
		$allow_online_member_edit_chk=convertChecked($a['allow_online_member_edit']);
		$allow_online_member_delete_chk=convertChecked($a['allow_online_member_delete']);
		
		$allow_branch_sales_add_chk=convertChecked($a['allow_branch_sales_add']);
		$allow_branch_sales_view_chk=convertChecked($a['allow_branch_sales_view']);
		$allow_branch_sales_edit_chk=convertChecked($a['allow_branch_sales_edit']);
		$allow_branch_sales_delete_chk=convertChecked($a['allow_branch_sales_delete']);
		$allow_online_sales_view_chk=convertChecked($a['allow_online_sales_view']);
		$allow_online_sales_edit_chk=convertChecked($a['allow_online_sales_edit']);
		$allow_online_sales_delete_chk=convertChecked($a['allow_online_sales_delete']);
		
		
		
		
?>
<table width="100%">
  
<td valign="top" align="left">
       <table width="95%" align="center">
	
	<tr>
		<td class="title"><?= $title ?></td>
	</tr>
	<tr>
		<td colspan="3" align="left">
             <form action="<?= $_SERVER['PHP_SELF'] ?>" method="post" name="addfrm" onSubmit="return frmvalidate(this)">
                Role Name : <input type="text" name="role_name" size="30" value="<?= $a['role_name'] ?>" maxlength="100">
                <br />
                
                <table>
                  <Tr>
                    <Td colspan="3"><strong>Home</strong></Td>
                  </Tr>
                  <tr valign="middle">
                     <td><input type="checkbox" name="accessright[]" value="allow_statistic_view" align="absmiddle" <?= $allow_statistic_view_chk ?>/> Allow View Site Statistic</td><td></td> 
                  </tr>	
                   <tr>
                    <Td><br /></Td>
                  </tr>
                  <Tr>
                    <Td colspan="3"><strong>Product Management</strong></Td>
                  </Tr>
                  <tr valign="middle">
                     <td><input type="checkbox" name="accessright[]" value="allow_product_management" align="absmiddle" <?= $allow_product_management_chk ?> /> Allow Product Management</td><td></td> 
                  </tr>
                   <tr>
                    <td><input type="checkbox" name="accessright[]" value="allow_product_category" <?= $allow_product_category_chk ?> /> Allow Product Category Management</td><td></td> 
                    <td><input type="checkbox" name="accessright[]" value="allow_product_add" <?= $allow_product_add_chk ?> /> Allow Add Product</td><td></td> 
                    <td><input type="checkbox" name="accessright[]" value="allow_product_edit" <?= $allow_product_edit_chk ?> /> Allow Edit Product</td><td></td> 
                    <td><input type="checkbox" name="accessright[]" value="allow_product_delete" <?= $allow_product_delete_chk ?> /> Allow Delete Product</td><td></td>
                  </tr>
                   <tr>
                    <Td><br /></Td>
                  </tr>
                  <Tr>
                    <Td colspan="3"><strong>Gift / Coupons</strong></Td>
                  </Tr>		
                  <tr>
                    <td><input type="checkbox" name="accessright[]" value="allow_gift_management" <?= $allow_gift_management_chk ?> /> Allow Gift/Coupon Management</td><td></td>
                  </tr>
                  <tr>
                    <Td><br /></Td>
                  </tr>
                   <Tr>
                    <Td colspan="3"><strong>Offline Purchase Management</strong></Td>
                  </Tr>
                   <tr valign="middle">
                     <td><input type="checkbox" name="accessright[]" value="allow_branch_management" align="absmiddle" <?= $allow_branch_management_chk ?> /> Allow Offline Purchase Management</td><td></td> 
                  </tr>	
                   <tr>
                    <td><input type="checkbox" name="accessright[]" value="allow_branch_member_view" <?= $allow_branch_member_view_chk ?> /> Allow View Offline Member</td><td></td> 
                    <td><input type="checkbox" name="accessright[]" value="allow_branch_member_add" <?= $allow_branch_member_add_chk ?> /> Allow Add Offline Member</td><td></td> 
                    <td><input type="checkbox" name="accessright[]" value="allow_branch_member_edit" <?= $allow_branch_member_edit_chk ?> /> Allow Edit Offline Member</td><td></td> 
                    <td><input type="checkbox" name="accessright[]" value="allow_branch_member_delete" <?= $allow_branch_member_delete_chk ?> />Allow Delete Offline Member</td><td></td>
                  </tr>
                   <tr>
                    <td><input type="checkbox" name="accessright[]" value="allow_branch_sales_view" <?= $allow_branch_sales_view_chk ?> /> Allow View Offline Sales</td><td></td> 
                    <td><input type="checkbox" name="accessright[]" value="allow_branch_sales_add" <?= $allow_branch_sales_add_chk ?>  /> Allow Add Offline Sales</td><td></td> 
                    <td><input type="checkbox" name="accessright[]" value="allow_branch_sales_edit" <?= $allow_branch_sales_edit_chk ?>  /> Allow Edit Offline Sales</td><td></td> 
                    <td><input type="checkbox" name="accessright[]" value="allow_branch_sales_delete"  <?= $allow_branch_sales_delete_chk ?> /> Allow Delete Offline Sales</td><td></td> 
        
                  </tr>
                   <tr>
                    <Td><br /></Td>
                  </tr>
                  <Tr>
                    <Td colspan="3"><strong>E-Shopping Management</strong></Td>
                  </Tr>
                  
                  <tr valign="middle">
                     <td><input type="checkbox" name="accessright[]" value="allow_shopping_management" align="absmiddle" <?= $allow_shopping_management_chk ?>/> Allow E-Shopping Management</td><td></td> 
                  </tr>		
                 
                  <tr>
                    <td><input type="checkbox" name="accessright[]" value="allow_online_member_view" <?= $allow_online_member_view_chk ?> /> Allow View Online Member</td><td></td> 
                    <td><input type="checkbox" name="accessright[]" value="allow_online_member_edit" <?= $allow_online_member_edit_chk ?>/> Allow Edit Online Member</td><td></td> 
                    <td><input type="checkbox" name="accessright[]" value="allow_online_member_delete" <?= $allow_online_member_delete_chk ?>/> Allow Delete Online Member</td><td></td>
                  </tr>
                   <tr>
                    <td><input type="checkbox" name="accessright[]" value="allow_online_sales_view" <?= $allow_online_sales_view_chk ?>  /> Allow View Online Sales</td><td></td> 
                   
                    <td><input type="checkbox" name="accessright[]" value="allow_online_sales_edit"  <?= $allow_online_sales_edit_chk ?> /> Allow Edit Online Sales</td><td></td> 
                    <td><input type="checkbox" name="accessright[]" value="allow_online_sales_delete"  <?= $allow_online_sales_delete_chk ?> /> Allow Delete Online Sales</td><td></td> 
        
                  </tr>
                   <tr>
                    <Td><br /></Td>
                  </tr>
                   <Tr>
                    <Td colspan="3"><strong>Shipping</strong></Td>
                  </Tr>		
                  <tr>
                    <td><input type="checkbox" name="accessright[]" value="allow_shipping_management"  <?= $allow_shipping_management_chk ?> /> Allow Shipping Management</td><td></td> 
                    
                  </tr>
                   <tr>
                    <Td><br /></Td>
                  </tr>
                  <Tr>
                    <Td colspan="3"><strong>Content</strong></Td>
                  </Tr>		
                  <tr>
                    <td><input type="checkbox" name="accessright[]" value="allow_content_management"  <?= $allow_content_management_chk ?>  /> Allow Content Management</td><td></td>
                  </tr>
                  <tr>
                    <Td><br /></Td>
                  </tr>
                  <Tr>
                    <Td colspan="3"><strong>User</strong></Td>
                  </Tr>		
                  <tr>
                    <td><input type="checkbox" name="accessright[]" value="allow_user_management"  <?= $allow_user_management_chk ?> /> Allow User Management</td><td></td> 
                    
                  </tr>
                   <tr>
                    <Td><br /></Td>
                  </tr>
                  <Tr>
                    <Td colspan="3"><strong>System</strong></Td>
                  </Tr>		
                  <tr>
                    <td><input type="checkbox" name="accessright[]" value="allow_system_management"  <?= $allow_system_management_chk ?> /> Allow System Management</td><td></td>  
                  </tr>
                </table>
                <br /><br />
                 <input type="hidden" name="id" value="<?= $a['id'] ?>">
                <input type="submit" value="Update" name="btnsubmit">
                &nbsp;
                 <input type="button" value="Back" onclick="history.go(-1)">
          </form>
		</td>
	</tr>
	</table>
	</td>
 
</table>
<? } require("required/footer.php"); ?>
